#ifndef __zg6907_H
#define __zg6907_H

#include "hw_abst.h"

#define read_head 0xfe
#define read_end 0xff
#define readback_head 0xfb

#define set_head 0xfd   //配置头
#define setback_head 0xfa   //配置返回头
#define back_error {0xf7,0xff}  //读取/设置失败
#define remote_head {0xa8,0x8a} //远程配置前缀
#define netSet_head 0xf5
#define netSet_end 0xff
#define netSetBack_head 0xfc

#define Set_mode {0x2a,0x2d,0x2e}
#define Trans_mode {0x2f,0x2c,0x2b}
#define ReadAllNetVal {0xfe,0x2f,0xfe,0xff}
#define ReBoot_Arr {0xfd,0x00,0x12,0xff}
#define Recovery_Arr {0xfd,0x00,0x13,0xff}

#define SET_AllNETValue_Coordinator {0xfd,0x1a,0xfe,0x01,0xff,0xfe,0x01,0x0b,0x14,0x09,0x54,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0x05,0x05,0xa8,0x8a,0xff}
#define SET_AllNETValue_Route {0xfd,0x1a,0xfe,0x02,0xff,0xfe,0x01,0x0b,0x14,0x09,0x54,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0x05,0x05,0xa8,0x8a,0xff}
#define SET_AllNETValue_Client {0xfd,0x1a,0xfe,0x03,0xff,0xfe,0x01,0x0b,0x14,0x09,0x54,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0xff,0x05,0x05,0xa8,0x8a,0xff}
#define SET_AllNETValue_SleepClient {0xfd,0x1a,0xfe,0x04,0xff,0xfe,0x01,0x0b,0x06,0x09,0x54,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0xff,0x05,0x05,0xa8,0x8a,0xff}
typedef struct
{
	uint8_t Node_Yype;				//0x01协调器 0x02路由器 0x03终端 0x04休眠终端
	uint8_t NET_State;				//0x00无网络	0x01加入种	0x02已加入网络 0x03有网络无父节点	0x04离开网络ing
	uint16_t PAN_ID;					
	uint16_t Addr;						//短地址
	uint64_t MAC;							//长地址
	uint16_t Addr_Farther;		
	uint64_t MAC_Father;      
	uint8_t NET_GroupNum;			//组号
	uint8_t Channel;					//信道0x0b~0x1a（11~26 默认11）
	uint8_t TX_power;					//0~20dbm  默认20dbm
	uint8_t Baud_Rate;				//默认115200不要改
	uint8_t Sleep_Time;				//1~60s /（n-60）*10+60s
	uint16_t Target_Addr;			
	uint8_t Target_GroupNum;	
	uint64_t Target_MAC;			
	uint8_t Send_Mode;				//0x00广播 0x01组播 0x02短点播 0x03长点播 0x04协议短点 0x05协议组播
	uint8_t Output_Mode;			//0x00透传 0x01+短地址 0x02+长地址 0x03+RSSI	 0x04短+RSSI 	0x05长+RSSI
	uint8_t Father_SaveTime;	//s MAX：30s；要接收父节点数据sleeptime<Father_SaveTime
	uint8_t NET_Opentime;			//n*10s，默认255永久开放
	uint8_t Rejoin_Circle;		//min 默认5min 1~255
	uint8_t Rejoin_Count;			//0~255 0不重连，255始终重连
	uint16_t Wireless_ID;			//默认：0xA8 0x8A
	uint8_t Child_Num;				//MAX：50
	uint8_t AUX_delayTime;		//ms 默认4ms
	uint8_t Uart_Holdtime;		//Value*10ms；默认100，即1000ms后休眠
	
	uint8_t Module_Mode;			//模块工作模式：0传输模式、1配置模式
}ZG_Module;


uint8_t Switch_to_SetMode(void);
uint8_t Switch_to_TransMode(void);
uint8_t ReBoot_Module(void);
uint8_t Read_SingleNET_Value(uint8_t * Cmd,uint8_t Num,uint8_t *back);
uint8_t Read_AllNet_Value(void);
uint8_t SET_SingleValue(uint8_t * Cmd,uint8_t Num);
uint8_t SET_ALLValue(void);
uint8_t NWK_Operate(uint8_t CMD_num);
uint8_t Nodetype_Switch(uint8_t Type_num);
uint8_t PANID_Channel_SET_Inside(uint16_t Target_PANID,uint8_t Target_Channel);//下面函数的Inside函数
uint8_t PANID_Channel_SET(uint16_t Target_PANID,uint8_t Target_Channel);//调用时请使用这个，虽然这个函数只是调用两次Inside函数；
																																				//但是Inside一次不能完全修改，这个BUG测试多种方式不能消除，可能和模块内部实现有关，就这么用8；




#endif

